#include "schedule.h"

static struct task_struct *task[NUM_TASKS];
static struct task_struct init_task;

void schedule_init()
{
    unsigned int i;
    struct desc_struct *p;
    // init task[]
    p = (struct desc_struct *)0x5000;
    p += FIRST_TSS_ENTRY;
    for (i=0; i<NUM_TASKS; i++)
    {
        task[i] = NULL;
        p->a = p->b = 0;
        p++;
        p->a = p->b = 0;
        p++;  
    }

    // set ldt and tss
    init_task.ldt[0].a = 0;
    init_task.ldt[0].b = 0;
    init_task.ldt[1].a = 0x9f;
    init_task.ldt[1].b = 0xc0fa00;
    init_task.ldt[2].a = 0x9f;
    init_task.ldt[2].b = 0xc0f200;
    init_task.tss.back_link = 0;

    p = (struct desc_struct *)0x5000;
    p += FIRST_TSS_ENTRY;
    p->a = SET_DESC_LOW32((unsigned int)&(init_task.tss));
    p->b = SET_DESC_HIGH32((unsigned int)&(init_task.tss), 0x89);
    p = (struct desc_struct *)0x5000;
    p += FIRST_LDT_ENTRY;
    p->a = SET_DESC_LOW32((unsigned int)&(init_task.ldt));
    p->b = SET_DESC_HIGH32((unsigned int)&(init_task.ldt), 0x82);

    // clear NT flag
    CLEARNT();
    LTR(0);
    LLDT(0);    
}
